#include "Bible.h"
#include "Bible_Old_Testament.h"
#include "Bible_New_Testament.h"

DrawingCanvas *syscanvas;

WordWrapTextBox bible_pagebox;
ScrollingMenu menu;

string bible_beginpagetext;

int keyheldcount;

Page_Selection currpage;

void setupMenu()
{
	ArrayList<Option> options = ArrayList<Option>();
	options.add(Option("  Holy Bible",Title));
	options.add(Option("Old Testament",Old_Testament));
	options.add(Option("New Testament",New_Testament));
	
	menu = ScrollingMenu(options,0,0,15,19,syscanvas);
	menu.setBgColor(RGB(83,83,83));
	menu.setTextColor(white);
	menu.setSelColor(RGB(180,180,180));
}
void setupTextBox()
{
	bible_beginpagetext = "\n\n\n\n";
	bible_beginpagetext += "Let it be know that to anyone who should edit this sacred ";
	bible_beginpagetext += "document and pass it on you run the risk of facing hell in the ";
	bible_beginpagetext += "end because this book be not the words of men but the words ";
	bible_beginpagetext += "of god through the hands, eyes, and first hand account of men ";
	bible_beginpagetext += "who where chosen by god to deliver a message to anyone who";
	bible_beginpagetext += "would like to be with god when they depart from this world ";
	bible_beginpagetext += "I leave you with this god is good why cant we be too.";
	
	bible_pagebox = WordWrapTextBox(bible_beginpagetext,(7*15) + 3,2,53,26,syscanvas);
}
void onKeyReleased(string key)
{
	keyheldcount = 0;
}
void onKeyHeld(string key)
{
	if(keyheldcount < 30)
		keyheldcount++;
	else
	{
		if(key == "L")
			bible_pagebox.scrollUp();
		else if(key == "R")
			bible_pagebox.scrollDown();
		else if(key == "down")
			menu.moveCurserDown();
		else if(key == "up")
			menu.moveCurserUp();
	}
}
void onKeyPressed(string key)
{
	keyheldcount = 0;
	if(key == "down")
	{
		menu.moveCurserDown();
	}
	else if(key == "up")
	{
		menu.moveCurserUp();
	}
	else if(key == "L")
	{
		bible_pagebox.scrollUp();
	}
	else if(key == "R")
	{
		bible_pagebox.scrollDown();
	}
	else if(key == "cross")
	{
		evalSelected();
	}
	else if(key == "triangle")
	{
		if(currpage == Old_Testament || currpage == New_Testament)
		{
			currpage = Book_Selection;
			ArrayList<Option> options = ArrayList<Option>();
			options.add(Option("  Holy Bible",Title));
			options.add(Option("Old Testament",Old_Testament));
			options.add(Option("New Testament",New_Testament));
			menu.setOptions(options);
			bible_pagebox.setText(bible_beginpagetext);
		}
		else if(currpage == Book_Old)
		{
			currpage = Old_Testament;
			menu.setOptions(getOldTestamentOptions());
			bible_pagebox.setText("This Book has not yet been finished");
		}
		else if(currpage == Book_New)
		{
			currpage = New_Testament;
			menu.setOptions(getNewTestamentOptions());
			bible_pagebox.setText("");
		}
		
	}
}
void evalSelected()
{
	int sel = menu.selected.num;
	if(sel == Old_Testament)
	{
		menu.setOptions(getOldTestamentOptions());
		bible_pagebox.setText("This Book has not yet been finished");
		currpage = (Page_Selection)sel;
	}
	else if(sel == New_Testament)
	{
		menu.setOptions(getNewTestamentOptions());
		bible_pagebox.setText("");
		currpage = (Page_Selection)sel;
	}
	else if(sel == Book_Old)
	{
		currpage = (Page_Selection)sel;
		menu.setOptions(getBook_OldOptions(menu.selected.text));
		bible_pagebox.setText("");
	}
	else if(sel == Book_New)
	{
		currpage = (Page_Selection)sel;
		menu.setOptions(getBook_NewOptions(menu.selected.text));
		bible_pagebox.setText("");
	}
	else if(sel == Book_Chapter)
	{
		string str;
		ArrayList<string> s = ArrayList<string>(getFileData(menu.selected.value.c_str()));
		for(int i = 0; i < s.size(); i++)
		{
			str += s.get(i); str += "\n";
		}
		bible_pagebox.setText(str);
	}
}
